import {
  ElButton as Button,
  ElSwitch as Switch,
  ElMessageBox as messageBox,
  ElMessage as message,
} from 'element-plus'
import { formatDate } from '@/utils'
export default (
  handeEdit?: Function,
  handleDel?: Function,
  t?: (arg0: string) => string
) => [
  {
    prop: 'username',
    label: '用户名',
  },
  {
    prop: 'roleName',
    label: '角色名',
  },
  {
    prop: 'deptName',
    label: '所属部门',
  },
  {
    prop: 'mobile',
    label: '手机号',
  },
  {
    prop: 'status',
    label: '状态',
    render(h: any, scope: { $index: any, row: any }) {
      const { $index: index, row } = scope
      return (
        <>
          <Switch
            model-value={row.status == '0'}
            onChange={(val) => {
              console.log('val', val)
              messageBox
                .confirm(
                  val
                    ? `确定要开启用户名为"${row.username}"的数据项吗?`
                    : `确定要禁用用户名为"${row.username}"的数据项吗?`,
                  '提示',
                  {
                    icon: (
                      <>
                        <i class="iconfont icon-jinggao"></i>
                      </>
                    ),
                    confirmButtonText: t!('messageBox.determine'),
                    cancelButtonText: t!('messageBox.cancel'),
                    type: 'warning',
                  }
                )
                .then(() => {
                  setTimeout(() => {
                    message({
                      type: 'success',
                      message: val ? '开启成功' : '禁用成功',
                    })
                  }, 300)
                })
                .catch(() => {
                  message({
                    type: 'info',
                    message: val ? '取消开启' : '取消禁用',
                  })
                })
            }}
            inline-prompt={true}
            active-text="开启"
            inactive-text="禁用"
          ></Switch>
        </>
      )
    },
  },
  {
    prop: 'createdAt',
    label: '创建时间',
    render(h: any, scope: { $index: any; row: any }) {
      const { $index: index, row } = scope
      return (
        <>
          {row.createdAt
            ? formatDate(new Date(row.createdAt).getTime(), 'Y/M/D h:m:s')
            : null}
        </>
      )
    },
  },
  {
    prop: 'updatedAt',
    label: '更新时间',
    render(h: any, scope: { $index: any; row: any }) {
      const { $index: index, row } = scope
      return (
        <>
          {row.updatedAt
            ? formatDate(new Date(row.updatedAt).getTime(), 'Y/M/D h:m:s')
            : null}
        </>
      )
    },
  },
  {
    prop: 'action',
    label: '操作',
    render(h: any, scope: { $index: any; row: any }) {
      const { $index: index, row } = scope
      return (
        <div>
          <Button
            type="primary"
            link
            onClick={() => {
              ;(handeEdit as Function)(row)
            }}
          >
            {t!('table.edit')}
          </Button>
          <Button
            type="primary"
            link
            onClick={() => {
              ;(handleDel as Function)(row)
            }}
          >
            {t!('table.delete')}
          </Button>
        </div>
      )
    },
  },
  {
    type: 'langs',
    path: 'views/system/account/config/columns',
  },
]
